/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pkg496_spu;

/**
 *
 * @author Yiwen Su
 */
public class debugging {

    math_utils math_utils = new math_utils();

    /*=============================Rounding (START)===========================*/
    public void debug_rounding() {
        double a = 0.234552;
        double b = 0.256284;
        double c = 0.287901;

        System.out.println("Rounding 0.234552: " + math_utils.round_1(a) + ", " + math_utils.round_2(a) + ", " + math_utils.round_3(a));
        System.out.println("Rounding 0.256284: " + math_utils.round_1(b) + ", " + math_utils.round_2(b) + ", " + math_utils.round_3(b));
        System.out.println("Rounding 0.287901: " + math_utils.round_1(c) + ", " + math_utils.round_2(c) + ", " + math_utils.round_3(c));
    }
    /*==============================Rounding (END)============================*/

    /*==============================Median (START)============================*/
    public void debug_median() {
        double[] array1 = {1.0, 2.0, 3.0}; //2.0
        double[] array2 = {1.0, 2.5, 3.0, 4.0}; //2.75

        System.out.println("Median should be 2.0: " + math_utils.median(array1));
        System.out.println("Median should be 2.75: " + math_utils.median(array2));
    }
    /*===============================Median (END)=============================*/

    /*========================Standard Deviation (START)======================*/
    public void debug_stddev() {
        double[] array1 = {5.0, 5.0, 5.0, 5.0, 5.0}; //0.0
        double[] array2 = {0.21, 0.22, 0.20, 0.23, 0.22, 0.51, 0.24, 0.23, 0.22, 0.22}; //Realistic sensor scenario

        System.out.println("No deviation test: " + math_utils.std_dev(array1, math_utils.mean(array1)));
        System.out.println("Std dev test: " + math_utils.std_dev(array2, math_utils.mean(array2)));
    }
    /*=========================Standard Deviation (END)=======================*/

    /*=========================Sample filtering (START)=======================*/
    public void debug_filter() {
        double[] array1 = {0.50, 0.50, 0.48, 0.35, 0.25, 0.22, 0.15, 0.20, 0.30, 0.35};
        double[] array2 = {0.23, 0.56, 0.30, 0.25, 0.22, 0.21, 0.22, 0.23, 0.24, 0.22};
        double mean1;
        double mean2;

        spu spu = new spu();

        mean1 = spu.spu(array1);
        System.out.println("Distance from object: " + mean1 + "m");
        mean2 = spu.spu(array2);
        System.out.println("Distance from object: " + mean2 + "m");
        
//        mean1 = math_utils.sample_filter(array1);
//        System.out.println("No filtering here: " + mean1);
//        array_dump(array1);

//        mean2 = math_utils.sample_filter(array2);
//        System.out.println("The last one should be 0.25: " + mean2);
//        array_dump(array2);
    }
    /*==========================Sample filtering (END)========================*/

    /*=======================Dump array values (START)========================*/
    private void array_dump(double[] array) {
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i] + ", ");
        }
    }
    /*========================Dump array values (END)=========================*/
}
